package com.hzdl.car.controller;

import com.hzdl.car.util.ZXingUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.OutputStream;

@Controller
@RequestMapping("test")
public class TestController {
    @RequestMapping("toImg")
    public String toImg(){
        return "test";
    }

    @RequestMapping("img")
    @ResponseBody
    public void img(HttpServletResponse response){
        try {
            OutputStream os=response.getOutputStream();
            BufferedImage image= ZXingUtil.createZXingCode("th",300,300);
            ImageIO.write(image,"JPEG",os);
            os.flush();
            os.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
